import 'package:base_flutter/base_flutter.dart';
import 'package:ls_work/net/api/http_api.dart';
import 'package:ls_work/net/post_request.dart';
import 'package:ls_work/net/response/new_health/health_record_list_data.dart';

import '../../a_yyt/models/health_record_entity.dart';

class HealthModel extends BaseMvvmModel {
  @override
  void onCleared() {}

  ///体征登记
  Future<Map> submitHealthSign(Map healthMap) async {
    var data = await HttpGo.instance.postData(HttpApi.createBean,
        data: healthMap.toJsonMapStr(), options: PostRequest.urlencodedHeader);
    if ("0" == data['code']) {
      return data;
    } else {
      throw data['msg'];
    }
  }

  Future<List<HealthRecordInfo>> healthRecordList({dynamic customerId,int page = 1,int rows = 20}) async {
    var map = {
      "customerId":customerId,
      "page":page,
      "rows":rows,
    };
    var data = await HttpGo.instance.postData(HttpApi.healthReportList,data: map,options: PostRequest.urlencodedHeader);
    if("0"==data['code']){
      return ((data['data']['rows'] as List?)??[]).map((e) => HealthRecordInfo.fromJson(e)).toList();
    }else{
      throw data['msg'];
    }
  }

  ///体征登记记录
  Future<List<HealthRecordListData>> healthRecord({
    dynamic buildingId,
    dynamic floorId,
    String customerNameLike = "",
    String? collectionTime,
    dynamic dataTypeIdStr,
    int page = 1,
    int rows = 20
  }) async {
    var map = {
      "buildingId":buildingId,
      "floorId":floorId,
      "customerNameLike":customerNameLike,
      "collectionTime":collectionTime,
      "dataTypeIdStr":dataTypeIdStr,
      "page":page,
      "rows":rows,
    };
    var data = await HttpGo.instance.postData(HttpApi.healthRecord,data: map,options: PostRequest.urlencodedHeader);
    if("0"==data['code']){
      return ((data['data']['rows'] as List)??[]).map((e) => HealthRecordListData.fromJson(e)).toList();
    }else{
      throw data['msg'];
    }
  }
}
